/*
 * table_protocol.cpp
 *
 *  Created on: 13.06.2013
 *      Author: SpirTanol
 */

#include "ui/table_protocol.h"
#include "ui/models/protocol_model.h"
#include "ui/detail_dialog.h"

// QT
#include <QHeaderView>
#include <QMouseEvent>
//=========================================================================================
TableProtocol::TableProtocol(QVector<ProtocolEvent*> *protocol, QWidget *parent) : QTableView(parent)
{
	setModel(new ProtocolModel(protocol, this));
	verticalHeader()->hide();
	setEditTriggers(QAbstractItemView::NoEditTriggers);
	setColumnWidth(1, 400);

	verticalHeader()->setDefaultSectionSize(16);
}

TableProtocol::~TableProtocol()
{

}

void TableProtocol::updateProtocol()
{
	static_cast<ProtocolModel*>(model())->updateProtocol();
}
//=========================================================================================
void TableProtocol::mouseDoubleClickEvent(QMouseEvent *event)
{
	ProtocolEvent *e = static_cast<ProtocolModel*>(model())->eventOf(indexAt(event->pos()));

	if (e)
	{
		DetailDialog *w = new DetailDialog(e);
		w->exec();
		delete w;
	}
}
